package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;


public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 

    public DvdUI()
    {
        //Constructor.
        dvdCtr = dvdCtr.getInstance();
    }

    public void start()
    {
        //Starts the dvd menu.
        dvdMenu();
    }

    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit) //that is: while exit is false
        {
            //show menu and return the user's choise
            int choice =   writeDVDMenu();
            switch(choice)
            {
            case 1:
                findDVD();
                break;
            case 2:
                createDVD();
                break;
            case 3:
                createCopy();
                break;
            case 4:
                deleteDVD();
                break;
            case 5:
                listAllDvds();
                break;
            case 6:
                //Does nothing and goes to default.
            default:
                exit=true; break;
            }
        }//end while.
    }

    private int writeDVDMenu()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** DVD Menu ***");
        System.out.println(" (1) Show DVD information");
        System.out.println(" (2) Create DVD ");
        System.out.println(" (3) Create DVD Copy");
        System.out.println(" (4) Delete DVD");
        System.out.println(" (5) Show current DVD list");
        System.out.println(" (6) Return");
        System.out.print("\n Make your choice: ");

        int choice = keyboard.nextInt();
        return choice;
    }

    private int inputDVDNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type ID number: ");
        int no = keyboard.nextInt();
        return no;
    }

    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }

    private String inputArtist()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Artist name: " );
        String title = keyboard.nextLine();
        return title;
    }

    private String inputPublishDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Publication Date: " );
        String title = keyboard.nextLine();
        return title;
    }

    private String inputCopyNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the Serial Number for the copy: ");
        String no = keyboard.nextLine();
        return no;
    }

    private String inputPurchasePrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Purchase Price: " );
        String title = keyboard.nextLine();
        return title;
    }
    //there is need for more methods to read information about DVDs
    //and methods to display the information

    private void findDVD()
    {   
        //Searches for a dvd.
        int no = inputDVDNo();
        String dvd = dvdCtr.findDVD(no);
        System.out.println(dvd);
        System.out.println("Press 'Enter' to return.");
        Scanner keyboard = new Scanner(System.in);
        keyboard.nextLine();
    }

    private void createDVD()
    {
        //Adds a new dvd to the database.
        long id = inputDVDNo();
        String title = inputTitle();
        String artist = inputArtist();
        String date = inputPublishDate();
        dvdCtr.createDVD(id,title,artist,date);

    }

    private void createCopy()
    {   
        //Creates a copy of an existing dvd.
        long id = inputDVDNo();
        String serial = inputCopyNo();
        String price = inputPurchasePrice();
        String date = inputPublishDate();
        dvdCtr.createCopy(id,serial,date,price);
    }

    private void deleteDVD()
    { 
        //Removes a dvd from the database.
        long id = inputDVDNo();
        dvdCtr.deleteDVD(id);
    }

    private void listAllDvds()
    {
       //Prints a list of all dvds.
       String str=dvdCtr.listAllDvds();
       System.out.println(str);
       System.out.println("Press 'Enter' to return.");   
       Scanner keyboard = new Scanner(System.in); 
       keyboard.nextLine();
    }
}